<template>
	<iframe v-if="loading" :src="url" frameborder="0" style="width: 100%; height: 100%"></iframe>
</template>
<script setup>
	import claimApi from '@/api/biz/claimApi'
	import { useRouter } from 'vue-router'
	import { globalStore } from '@/store'

	const store = globalStore()
	const router = useRouter()
	const loading = ref(false)
	const url = ref('')
	claimApi.getThird().then((res) => {
		url.value = `https://aicustomers-third-data.qike366.com/user/loginbythird?url=/market&thirdUid=${store.userInfo.id}&authId=${res.authId}&auth=${res.auth}`
		loading.value = true
	})
	onMounted(() => {
		window.addEventListener('message', receiveMsg, false)
	})
	onBeforeUnmount(() => {
		window.removeEventListener('message', receiveMsg, false)
	})
	const receiveMsg = (e) => {
		if (e.data.type === 'goto') {
			if (e.data.url === 'receive') {
				router.push('/biz/claimList')
			}
		}
	}
</script>
